﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using infoMngmntGUI.Control;

namespace infoMngmntGUI.View 
{
    /// <summary>
    /// Interaction logic for LogIn.xaml
    /// </summary>
    public partial class Login : IView
    {
        private AccessManagement accessManager;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="accessManager"></param>
        public Login(AccessManagement accessManager) : base()
        {
            this.minimumAccess = Control.AccessManagement.UserType.NOTLOGGEDIN;
            this.accessManager = accessManager;
            InitializeComponent();
        }

        /*
         * 
         */
        private void Attempt_To_Login(object sender, RoutedEventArgs e)
        {
            string user = userName_field.Text;
            string pass = password_field.Password;
            if (!accessManager.Login(user, pass))
            {
                MessageBox.Show("Password Incorrect", "Your Username Or Password was incorrect", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                MessageBox.Show("You have been successfully logged in", "Login Successful", MessageBoxButton.OK, MessageBoxImage.Information);
                userName_field.Text = "";
                userName_field.IsEnabled = false;
                password_field.Password = "";
                password_field.IsEnabled = false;
                loginButton.IsEnabled = false;
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return "Log In";
        }

        /*
         * When the user clicks on the username field, remove the "watermark"
         */
        private void userName_field_GotFocus(object sender, RoutedEventArgs e)
        {
            userName_field.Text = "";
            userName_field.Foreground = Brushes.Black;
        }
    }
}
